package com.approval.approvalapp.index.dbsx.ptbl.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.PtblDbBean;
import com.approval.approvalapp.index.dbsx.ptbl.activity.PtblXqDbActivity;
import com.approval.approvalapp.index.dbsx.ptbl.activity.PtblXqYbActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/4/29.
 */

public class PtblybAdapter extends RecyclerView.Adapter<PtblybAdapter.Holder> {
    List<PtblDbBean> ptblDbBeanList;

    Context context;

    public void setPtblDbBeanList(List<PtblDbBean> ptblDbBeanList) {
        this.ptblDbBeanList = ptblDbBeanList;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_ptblyb,parent,false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final Holder holder, final int position) {
        holder.tv1.setText("申报事项: " + ptblDbBeanList.get(position).getApply_subject());

        holder.tv5.setText("申报时间: " + ptblDbBeanList.get(position).getReceive_time());

        holder.tv4.setText("申请人: " + ptblDbBeanList.get(position).getApplicant());

        holder.tvywc.setText(ptblDbBeanList.get(position).getCurrent_node_name());


        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, PtblXqYbActivity.class);
                intent.putExtra("business_object_code", ptblDbBeanList.get(position).getBusiness_object_code());
                intent.putExtra("business_object_type",ptblDbBeanList.get(position).getBusiness_object_type());
                intent.putExtra("item_id",ptblDbBeanList.get(position).getItem_id());
                intent.putExtra("bsnum",ptblDbBeanList.get(position).getBsnum());

                intent.putExtra("sbsx",holder.tv1.getText().toString());
                intent.putExtra("blsx",ptblDbBeanList.get(position).getItem_name());
                intent.putExtra("sbsj",ptblDbBeanList.get(position).getReceive_time());
                intent.putExtra("sqr",ptblDbBeanList.get(position).getApplicant());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (ptblDbBeanList == null){
            return 0;
        }else {
            return ptblDbBeanList.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder{
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.tv5)
        TextView tv5;
        @Bind(R.id.root)
        LinearLayout root;
        @Bind(R.id.tvywc)
        TextView tvywc;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
